<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>HTMLDOM 控制样式</title>
    <style>
        .d1{
            border:1px solid red;
            width: 100px;
            height: 100px;
        }
        .d2{
            border:1px solid dodgerblue;
            width: 200px;
            height: 200px;
        }
    </style>
</head>
<body>
<div id="div1">
    div1
</div>
<div id="div2">
    div2
</div>
<script>
    var div1 = document.getElementById("div1");
    div1.onclick=function () {
        //修改样式方式1 使用元素的style属性
        div1.style.border ="1px solid red"
        div1.style.width = "200px"
        div1.style.fontSize = "20px"

    }

    var div2 = document.getElementById("div2");
    div2.onclick=function () {
        //修改样式方式2  提前定义好类选择器的样式，通过元素的classname属性设置classname属性值
        div2.className = "d2";

    }
</script>
</body>
</html>